<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/common/taglibs.jsp" %>
<%@ taglib prefix ="s" uri="/struts-tags"%>
<!DOCTYPE html>
<html lang="en">
	<head>
		<%@ include file="/common/common-css.jsp"%>
		
		<link rel="stylesheet" href="/loan_manager/css/common-loading.css">
		
		<style>
			#jquery-table td {
				cursor: pointer !important
			}
			
			.productthumbnail {
				width: 100px;
				height: 100px;
			}
			
			@media (min-width: 768px) and (max-width: 1200px) {
				.backup-text {
					width: 100px !important;
				}
			}
		</style>
	</head>
	<body  class="no-skin">
		<%@ include file="/common/common-loading.jsp"%>
		<div class="page-content">
			<div class="page-header" style="margin-bottom:0px;padding-bottom:10px;">
				<h1 id="fu_name">
				</h1>
			</div>
			<form id="queryForm" method="post">
			<div class="page-content-area">
				<div class="row">
					<div class="col-sm-12">
						<div class="widget-box" style="border:0px solid #ccc; border-top:none;border-bottom:none;">
							<div class="widget-header widget-header-blue widget-header-flat">
								<h4 class="widget-title">通用活动注册统计</h4>
		
								<div class="widget-toolbar">
									<a href="#" data-action="collapse">
										<i class="ace-icon fa fa-chevron-up"></i>
									</a>
								</div>
							</div>
		
							<div class=" widget-body">
									<div class="widget-main" >
									
										
										<div class="form-group col-xs-12 col-sm-4">
											<label class="col-sm-2 control-label"
												style="text-align: right" for="prdid">产品</label>
											<div class="col-sm-6" style="padding-left: 0;">
												<select id="prdid" name="prdid" class="form-control"></select>
											</div>
										</div>

										<div class="form-group col-xs-12 col-sm-4">
											<label class="col-sm-2 control-label"
												   style="text-align: right" for="parentProduct">产品分类</label>
											<div class="col-sm-6" style="padding-left: 0;">
												<select id="parentProduct" name="parentProduct" class="form-control"></select>
											</div>
										</div>
										
										<div class="form-group col-xs-12 col-sm-4">
											<label class="col-sm-2 control-label"
												   style="text-align: right" for="platform">平台</label>
											<div class="col-sm-6" style="padding-left: 0;">
												<select class="form-control" name="platform" id="platform">
													<option value="">通用</option>
													<option value="android">安卓</option>
													<option value="ios">ios</option>
												</select>
											</div>
										</div>
										
										<div class="form-group col-xs-12 col-sm-4">
											<label class="col-sm-2 control-label"
												style="text-align: right" for="channel">渠道</label>
											<div class="col-sm-6" style="padding-left: 0;">
												<select id="channel" name="channel"></select>
											</div>
										</div>
										
										<div class="form-group col-xs-12 col-sm-4">
											<label class="col-sm-2 control-label"
												   style="text-align: right" for="channelGroup">渠道分类</label>
											<div class="col-sm-6" style="padding-left: 0;">
												<select id="channelGroup" name="channelGroup"></select>
											</div>
										</div>

										<div class="form-group col-xs-12 col-sm-4">
											<label class="col-sm-2 control-label"
												   style="text-align: right" for="secondaryChannelGroup">二级渠道分类</label>
											<div class="col-sm-6" style="padding-left: 0;">
												<select id="secondaryChannelGroup" name="secondaryChannelGroup"></select>
											</div>
										</div>
										
										<div class="form-group col-xs-12 col-sm-4">
											<label class="col-sm-2 control-label"
												style="text-align: right" for="activity_id">活动id:</label>
											<div class="col-sm-6" style="padding-left: 0;">
												<input type="text" style="padding-left: 0px" name="activity_id" id="activity_id">
											</div>
										</div>
										
										<div class="form-group col-xs-12 col-sm-4">
											<label class="col-sm-2 control-label"
												style="text-align: right" for="activity_type">活动类型:</label>
											<div class="col-sm-6" style="padding-left: 0;">
												<select class="form-control" name="activity_type" id="activity_type">
													<option value="">请选择</option>
													<option value="1">渠道推广</option>
													<option value="2">联登推广/旧</option>
													<option value="3">联登推广/新</option>
													<option value="4">API推广</option>
													<option value="5">征信推广</option>
													<option value="6">新外部推广页</option>
													<option value="7">速来贷推广页</option>
												</select>
											</div>
										</div>
										
										<div class="form-group col-xs-12 col-sm-4">
											<label class="col-sm-2 control-label"
												style="text-align: right" for="environment">请求环境:</label>
											<div class="col-sm-6" style="padding-left: 0;">
												<select class="form-control" name="environment" id="environment">
													<option value="">请选择</option>
													<option value="1">H5推广</option>
													<option value="2">客户端</option>
												</select>
											</div>
										</div>
										
										<div class="form-group col-xs-12 col-sm-4 "> 
												<label class="col-sm-2 control-label"  style="text-align:right">时间:</label>
												<div class="col-sm-6">
													<div class="input-daterange input-group col-sm-12">
														<input type="text" data-date-format="yyyy-mm-dd" 
															class="fromDate date-picker input-sm form-control" style="padding-left:0px" name="startDate">
														<span class="input-group-addon" style="width:6px">
															<i class="fa fa-exchange"></i>
														</span>
														<input type="text" data-date-format="yyyy-mm-dd" 
															class="endDate date-picker input-sm form-control" style="padding-left:0px" name="endDate">
													</div>
												</div>
										</div>
										
									</div>
							</div>
						</div>
					</div>
						<div class="col-md-12 center">
						<div class="clearfix form-actions">
						
							<button class="btn btn-purple  no-border" type="button" name="btn-query" onclick="query_any()" id="btn-query">
								<i class="ace-icon fa fa-search icon-on-right bigger-110"></i>
								查询
							</button>
							&nbsp;&nbsp;&nbsp;
							<button class="btn btn-grey btn-lg no-border" type="reset">
								<i class="ace-icon fa fa-undo icon-on-right bigger-110"></i>
								重置
							</button>
							&nbsp;&nbsp;&nbsp;
							 <button class="btn btn-purple no-border" type="button" name="btn-query" id="exportList">
                            	<i class="ace-icon fa fa-undo icon-on-right bigger-110"></i>
                            	导出
                        	</button>
                        	&nbsp;&nbsp;&nbsp;
							 <button class="btn btn-purple no-border" type="button" name="btn-query" id="instantStatistics">
                            	<i class="ace-icon fa fa-undo icon-on-right bigger-110"></i>
                            	即时统计数据
                        	</button>
							
						  </div>
				   </div>
				</div>
		 		<div class="row">
					<div class="col-xs-12">
						<table id="jquery-table" class="table table-striped table-bordered table-hover">
						</table>
					</div>
				</div>
			</div>
			</form>
		</div>
	</body>
</html>

<%@ include file="/common/common-js.jsp" %>
<!-- loading js -->
<script type="text/javascript" src="${ctx}/js/common-loading.js"></script>
<script type="text/javascript" src="${ctx}/js/call_func.js"></script>
<link rel="stylesheet" href="${ctx}/ace/css/just-tip.css"/>
<script src="${ctx}/ace/js/justTools.js"></script>

<!-- inline scripts related to this page -->
<script type="text/javascript">

    function loadParentProduct() {
        $.ajax({
            type : 'POST',
            dataType : 'json',
            url : ctx + "/getQueryCondition/getParentProductList.action?rand="
            + Math.random(),
            timeout : 300000,
            success : function(resp) {

                var data = resp["aaData"];
                var parentProduct = '<option value="">请选择</option>';

                for (var i = 0; i < data.length; i++) {
                    parentProduct += '<option value="' + data[i]["parentProductId"] + '">'
                        + data[i]["parentProductName"] + '</option>';
                }
                $("#parentProduct").html(parentProduct);
            },
        });
    }

    function loadChannelGroup() {
        $.ajax({
            type : 'POST',
            dataType : 'json',
            url : ctx + "/getQueryCondition/getChannelGroupList.action?rand="
            + Math.random(),
            timeout : 300000,
            success : function(resp) {

                var data = resp["aaData"];
                var channelGroup = '<option value="">请选择</option>';

                for (var i = 0; i < data.length; i++) {
                    channelGroup += '<option value="' + data[i]["channelGroupId"] + '">'
                        + data[i]["channelGroupName"] + '</option>';
                }
                $("#channelGroup").html(channelGroup);
            },
        });
    }

	function loadSecondaryChannelGroup() {
		$.ajax({
			type : 'POST',
			dataType : 'json',
			url : ctx + "/getQueryCondition/getSecondaryChannelGroupList.action?rand="
					+ Math.random(),
			timeout : 300000,
			success : function(resp) {

				var data = resp["aaData"];
				var secondaryChannelGroup = '<option value="">请选择</option>';

				for (var i = 0; i < data.length; i++) {
					secondaryChannelGroup += '<option value="' + data[i]["id"] + '">'
							+ data[i]["channelName"] + '</option>';
				}
				$("#secondaryChannelGroup").html(secondaryChannelGroup);
			},
		});
	}

    //【查询】按钮Click事件
	function query_any(){
	 	$("#output").removeAttr("style");
		if(jqTable != null){
			jqTable.fnDraw();
		} else {
			loaddata();
		}
		 $("#delete_btn").attr("style","display:block");
		 $("#delete_hr").attr("style","margin-top:0px;margin-bottom:20px;display:block");
	 };
	
	 var jqTable = null;
	 var loaddata = function(){
		jQuery(function($) {
			jqTable = $('#jquery-table').dataTable( {
			    //数据列控制（包括对应返回JSON属性名称，对应表头列索引位置、数据转换封装等）
			    "columnDefs": [
					{	  
						  "title":'日期',
						  "name":"createDate",
						  "data": "createDate",
						  "targets": [0],
						  "class": "center",
						  "bSortable": false,
						  "width": "1%",
					},
					{	  
						  "title":'产品',
						  "name":"productName",
						  "data": "productName",
						  "targets": [1],
						  "class": "center",
						  "bSortable": false,
						  "width": "1%",
					},
                    {
                        "title":'产品分类',
                        "name":"productGroupName",
                        "data": "productGroupName",
                        "targets": [2],
                        "class": "center",
                        "bSortable": false,
                        "width": "1%",
                    },
					{	  
						  "title":'渠道',
						  "name":"channelName",
						  "data": "channelName",
						  "targets": [3],
						  "class": "center",
						  "bSortable": false,
						  "width": "1%",
					},
                    {
                        "title":'渠道分类',
                        "name":"channelGroupName",
                        "data": "channelGroupName",
                        "targets": [4],
                        "class": "center",
                        "bSortable": false,
                        "width": "1%",
                    },
					{
						"title":'二级渠道分类',
						"name":"secondaryChannelGroupName",
						"data": "secondaryChannelGroupName",
						"targets": [5],
						"class": "center",
						"bSortable": false,
						"width": "1%",
					},
					{	  
						  "title":'平台',
						  "name":"platform",
						  "data": "platform",
						  "targets": [6],
						  "class": "center",
						  "bSortable": false,
						  "width": "1%"
					},
					{	  
						  "title":'活动类型',
						  "name":"activityTypeName",
						  "data": "activityTypeName",
						  "targets": [7],
						  "class": "center",
						  "bSortable": false,
						  "width": "1%"
					},
					{	  
						  "title":'活动ID',
						  "name":"activityId",
						  "data": "activityId",
						  "targets": [8],
						  "class": "center",
						  "bSortable": false,
						  "width": "1%"
					},
					{	  
						  "title":'H5-登记人数',
						  "name":"h5CheckInCount",
						  "data": "h5CheckInCount",
						  "targets": [9],
						  "class": "center",
						  "bSortable": false,
						  "width": "1%"
					},
					{	  
						  "title":'H5-注册人数',
						  "name":"h5RegisterCount",
						  "data": "h5RegisterCount",
						  "targets": [10],
						  "class": "center",
						  "bSortable": false,
						  "width": "1%"
					},
					{	  
						  "title":'APP-注册人数（按设备）',
						  "name":"appRegisterCountDevice",
						  "data": "appRegisterCountDevice",
						  "targets": [11],
						  "class": "center",
						  "bSortable": false,
						  "width": "1%"
					},
					{	  
						  "title":'APP-注册人数（按手机号）',
						  "name":"appRegisterCountPhone",
						  "data": "appRegisterCountPhone",
						  "targets": [12],
						  "class": "center",
						  "bSortable": false,
						  "width": "1%"
					},
					{	  
						  "title":'api提单数',
						  "name":"apiOrderCount",
						  "data": "apiOrderCount",
						  "targets": [13],
						  "class": "center",
						  "bSortable": false,
						  "width": "1%"
					},
					{	  
						  "title":'api成功提单数',
						  "name":"apiOrderSuccessCount",
						  "data": "apiOrderSuccessCount",
						  "targets": [14],
						  "class": "center",
						  "bSortable": false,
						  "width": "1%"
					},
					{	  
						  "title":'借条提单数',
						  "name":"loanReceiptOrderCount",
						  "data": "loanReceiptOrderCount",
						  "targets": [15],
						  "class": "center",
						  "bSortable": false,
						  "width": "1%"
					},
                    {
                        "title":'访问UV',
                        "name":"uv",
                        "data": "uv",
                        "targets": [16],
                        "class": "center",
                        "bSortable": false,
                        "width": "1%"
                    },
                    {
                        "title":'登录人数',
                        "name":"loginCount",
                        "data": "loginCount",
                        "targets": [17],
                        "class": "center",
                        "bSortable": false,
                        "width": "1%"
                    },
                    {
                        "title":'登录人数/访问UV',
                        "name":"loginToUvRate",
                        "data": "loginToUvRate",
                        "targets": [18],
                        "class": "center",
                        "bSortable": false,
                        "width": "1%"
                    },
                    {
                        "title":'APP注册人数（按手机号）/访问UV',
                        "name":"appRegisterCountPhoneToUvRate",
                        "data": "appRegisterCountPhoneToUvRate",
                        "targets": [19],
                        "class": "center",
                        "bSortable": false,
                        "width": "1%"
                    }
			  	],
				"sAjaxSource": ctx+"/statCommActivityRetister/getList.action?rand=" + Math.random(),
				"fnServerData": function ( sSource, aoData, fnCallback ) {//从服务器请求数据
			   			var data = $('#queryForm').serializeObject();
						
						data.aoData = JSON.stringify(aoData);
						$.ajax({
							"type": "POST",
							"dataType": 'json',
							"url": sSource,
							"data":data,
							"timeout":300000,
							"beforeSend": function() {
								// 显示loading
								showLoading();
							},
							"success": function(resp){
								console.info(resp);
								hideLoading();
								fnCallback(resp);
								initListPage();
								
							},		
							"error": function(XMLHttpRequest, textStatus, errorThrown) {
								alert('请求服务器错误,请刷新重试！！');//错误提示，包括服务器重启导致的session失效
							},			
							"complete": function () {
								hideLoading();
							}
					});
				},
				"sScrollXInner": "100%",
				"sScrollY": "100%",//如果不设置，IE会有问题
			    "aaSorting": [[2,"desc"]] //初始化加载，默认按第几列排序、排序方式（列从0开始计算）
			});
			
			
		});
	}
	
	
	$(document).ready(function() {
		//时间范围插件初始化
			$('.date-picker').datepicker({
				autoclose : true,
				format : 'yyyy-mm-dd'
			});

		loadProduct();
		loadChannel();
        loadParentProduct();
        loadChannelGroup();
        loadSecondaryChannelGroup();
		$("#prdid").combobox();
		$("#channel").combobox();
        $("#parentProduct").combobox();
		$("#output").hide();
	});
	
	$('#exportList').click(function () {
	        var form = document.forms["queryForm"];
	        var url = ctx + "/statCommActivityRetister/exportList.action";
	        form.action = encodeURI(url);
	        form.submit();
	    });
	    
	$('#instantStatistics').click(function () {
	        $.ajax({
				type:"post",	
				async:true,
				url: ctx + "/statCommActivityRetister/instantStatistics.action?rand=" + Math.random(),
				success:function(resp){
					alert("即时统计成功");
					query_any();
				},
				error:function(error){
					alert("即时统计失败");
				}
			});
	        
	        
	    });
	
</script>